﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Runtime.InteropServices;

namespace SwAddinHelpers.ComHelpers
{
    public static class pinvoke
    {
        public const uint SB_SETTEXT = 1035;
        public const uint SB_SETPARTS = WM_USER + 4;
        public const uint SB_GETPARTS = WM_USER + 6;
        public const uint SB_GETTEXTLENGTH = WM_USER + 12;
        public const uint SB_GETTEXT = WM_USER + 13;

        //http://www.mjtnet.com/scripts/winmsgs.txt
        public const uint H_MAX = 0xFFFF;
        public const uint TCN_FIRST = H_MAX - 550;
        public const uint TCN_SELCHANGE = TCN_FIRST - 1;
        public const uint TCN_SELCHANGING = TCN_FIRST - 2;
        public const uint TCM_FIRST = 0x1300;
        public const uint TCM_SETCURFOCUS = 0x1330;
        public const uint TCM_DESELECTALL = 0x1332;
        public const uint TCM_GETCURSEL = TCM_FIRST + 11;
        public const uint TCM_SETCURSEL = TCM_FIRST + 12;
        public const uint WM_NOTIFY = 0x004E;
        public const uint WM_USER = 0x0400;

        [DllImport("user32.dll", CharSet = CharSet.Auto)]
        public static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, int wParam, IntPtr lParam);

        //http://download.microsoft.com/download/f/2/7/f279e71e-efb0-4155-873d-5554a0608523/CLRInsideOut2008_01.exe  
        [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)]
        public struct NMHDR
        {
            public IntPtr hwndFrom;
            public IntPtr idFrom;
            public uint code;
        }

        [DllImport("user32.dll")]
        public static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);

        [DllImport("user32.dll", CharSet = CharSet.Auto)]
        public static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, IntPtr lParam);

        [DllImport("user32.dll")]
        public static extern int GetDlgCtrlID(IntPtr hwndCtl);

        [DllImport("user32.dll")]
        public static extern bool FlashWindow(IntPtr hwnd, bool bInvert);

        [DllImport("user32.dll")]
        [return: MarshalAs(UnmanagedType.Bool)]
        public static extern bool FlashWindowEx(ref FLASHWINFO pwfi);

        [StructLayout(LayoutKind.Sequential)]
        public struct FLASHWINFO
        {
            public UInt32 cbSize;
            public IntPtr hwnd;
            public UInt32 dwFlags;
            public UInt32 uCount;
            public UInt32 dwTimeout;
        }

        //Stop flashing. The system restores the window to its original state.
        public const UInt32 FLASHW_STOP = 0;
        //Flash the window caption.
        public const UInt32 FLASHW_CAPTION = 1;
        //Flash the taskbar button.
        public const UInt32 FLASHW_TRAY = 2;
        //Flash both the window caption and taskbar button.
        //This is equivalent to setting the FLASHW_CAPTION | FLASHW_TRAY flags.
        public const UInt32 FLASHW_ALL = 3;
        //Flash continuously, until the FLASHW_STOP flag is set.
        public const UInt32 FLASHW_TIMER = 4;
        //Flash continuously until the window comes to the foreground.
        public const UInt32 FLASHW_TIMERNOFG = 12; 
    }
}
